﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model Domain.Dto.ArticleInfoDto
@{
    ViewBag.subtitle = "修改特惠活动";
    ViewBag.Title = "修改特惠活动";
}
<div id="divArticle">
    @using (Ajax.BeginForm("edit", "article", new AjaxOptions() { HttpMethod = "post", OnBegin = "checkedEditForm", OnSuccess = "editSuccess", OnFailure = "editFailure" }))
    {
        <fieldset class="module width_full">
            @Html.Partial("_Form", Model)
            <p>
                @{
        if (Html.HasUiPermission(this.ViewContext, "edit"))
        {
                    <input type="submit" value="修改" class='alt_btn module_margin' />
                    @Html.GoBackPre("t-button")
        }
                }
            </p>
        </fieldset>
    }
</div>
<script type="text/javascript">

    $(function () {
        $(":input[data-autocomplete]").each(function () {
            $(this).autocomplete({
                source: $(this).attr("data-autocomplete")
            });
        });
    });

    function checkedEditForm() {
        var res = true;
        if ($('#articleClass').val() == 0) {
            $('#articleClass').focus();
            alert("请选择分类");
            res = false;
            return res;
        }
        if ($('#Title').val() == "") {
            alert("标题不能为空");
            $('#Title').focus();
            res = false;
            return res;
        }
        return res;
    }

    function editSuccess(res) {
        if (res.success) {
            alert("修改成功");
        }
        else {
            if ($('#Title').val() == "") {
                $('#Title').focus();
            }
            if ($('#Content').val() == "") {
                $('#Content').focus();
            }
            alert(res.message);
        }
    }

    function editFailure() {
        alert("修改失败了T_T！");
    }

    $(document).ready(function () {
        var select = $('#isNotExpired').attr('checked');
        isNotExpired(select);
        $('#isNotExpired').click(function (e) {
            select = $(this).attr('checked');
            isNotExpired(select);
        });
    });

    function isNotExpired(select) {
        if (select != undefined) {
            //$('#ExpiredDateTime_wrapper').addClass('t-state-disabled').attr('disabled', 'disabled');
            $('#ExpiredDateTime').attr('style', 'background:#939291;');
            $('#isNotExpired').val('1');
        }
        else {
            //$('#ExpiredDateTime_wrapper').removeClass('t-state-disabled').removeAttr('disabled');
            $('#ExpiredDateTime').attr('style', 'background:;');
            $('#isNotExpired').val('0');
        }
    }
</script>
